<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
JsWs Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="codehost.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>JsWs</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>codehost.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'codehost.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="EvalCodeHost.html">EvalCodeHost</a></b></td>
    <td>Container for code executed in the context of a dynamic webpage.</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="ExFileLoadError.html">ExFileLoadError</a></b></td>
    <td>Exception class for file reading
 </td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="ExScriptLoadError.html">ExScriptLoadError</a></b></td>
    <td>Exception class for server side script loading
 </td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="ExScriptParseError.html">ExScriptParseError</a></b></td>
    <td>Exception class for server side script parsing
 </td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/* ***** BEGIN LICENSE BLOCK *****
 *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is JsWs.
 *
 * The Initial Developer of the Original Code is
 * Chris Winberry.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 * 
 * ***** END LICENSE BLOCK ***** */</span>

<span class="comment">/**
 * <span class="attrib">@class</span> Exception class for server side script parsing
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@base</span> ExBase
 * <span class="attrib">@param</span> {String} msg Description of exception
 * <span class="attrib">@param</span> {Number} code (optional) Error code
 * <span class="attrib">@param</span> {Exception} ex (optional) An earlier exception to wrap
 * <span class="attrib">@param</span> {Arguments} args (optional) Arguments array of a functions
 * <span class="attrib">@see</span> EvalCodeHost
 */</span>
<span class="reserved">function</span> ExScriptParseError (msg, code, ex, args) { ExScriptParseError.baseConstructor.call(<span class="reserved">this</span>, msg, code, ex, args); }
SubClass(ExBase, ExScriptParseError);

<span class="comment">/**
 * <span class="attrib">@class</span> Exception class for server side script loading
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@base</span> ExBase
 * <span class="attrib">@param</span> {String} msg Description of exception
 * <span class="attrib">@param</span> {Number} code (optional) Error code
 * <span class="attrib">@param</span> {Exception} ex (optional) An earlier exception to wrap
 * <span class="attrib">@param</span> {Arguments} args (optional) Arguments array of a functions
 * <span class="attrib">@see</span> EvalCodeHost
 */</span>
<span class="reserved">function</span> ExScriptLoadError (msg, code, ex, args) { ExScriptLoadError.baseConstructor.call(<span class="reserved">this</span>, msg, code, ex, args); }
SubClass(ExBase, ExScriptLoadError);

<span class="comment">/**
 * <span class="attrib">@class</span> Exception class for file reading
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@base</span> ExBase
 * <span class="attrib">@param</span> {String} msg Description of exception
 * <span class="attrib">@param</span> {Number} code (optional) Error code
 * <span class="attrib">@param</span> {Exception} ex (optional) An earlier exception to wrap
 * <span class="attrib">@param</span> {Arguments} args (optional) Arguments array of a functions
 */</span>
<span class="comment">//TODO: generalize this into file IO operation exceptions</span>
<span class="reserved">function</span> ExFileLoadError (msg, code, ex, args) { ExFileLoadError.baseConstructor.call(<span class="reserved">this</span>, msg, code, ex, args); }
SubClass(ExBase, ExFileLoadError);

<span class="comment">/**
 * <span class="attrib">@class</span> Container for code executed in the context of a dynamic webpage.
 *  Keeps script page variable/object scope locked to individual requests.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {JsWs} server JsWs server instance
 * <span class="attrib">@param</span> {Request} request Incoming request object
 * <span class="attrib">@param</span> {Response} response Outgoing response object
 * <span class="attrib">@param</span> {ScriptContext} script Scripting context object
 */</span>
<span class="reserved">function</span> EvalCodeHost (server, request, response, script) {
	<span class="comment">/** <span class="attrib">@type</span> JsWs */</span>
	<span class="reserved">this</span>.server = server;
	<span class="comment">/** <span class="attrib">@type</span> Request */</span>
	<span class="reserved">this</span>.request = request;
	<span class="comment">/** <span class="attrib">@type</span> Response */</span>
	<span class="reserved">this</span>.response = response;
	<span class="comment">/** <span class="attrib">@type</span> ScriptContext */</span>
	<span class="reserved">this</span>.script = script;
}


<span class="comment">/**
 * Runs cleanup on internal objects
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.destroy = <span class="reserved">function</span> () {
	<span class="reserved">this</span>.server = null;
	<span class="reserved">this</span>.request = null;
	<span class="reserved">this</span>.response = null;
	<span class="reserved">this</span>.script = null;
}


<span class="comment">/**
 * Parses a string that contains a mix of static text and/or
 * embedded script into pure JavaScript ready to be eval'd
 * <span class="attrib">@param</span> {String} code String to be parsed
 * <span class="attrib">@returns</span> JavaScript code ready to be evaluated
 * <span class="attrib">@type</span> String
 * <span class="attrib">@exception</span> ExScriptParseError
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.parse = <span class="reserved">function</span> (code) {
	var codeParsed = <span class="literal">""</span>;

	var codeParts = code.split(/&lt;\?js\s*/);

	<span class="reserved">for</span> (var i = 0; i &lt; codeParts.length; i++) {
		<span class="reserved">if</span> (!codeParts[i].length) { continue; }

		isCodeEnd = (i == 0 || i == codeParts.length);

		codeSectionParts = codeParts[i].split(/\s*\?&gt;/);
		<span class="reserved">if</span> (isCodeEnd &amp;&amp; codeSectionParts.length == 1) {
			codeSectionParts.unshift(<span class="literal">""</span>);
		}
		<span class="reserved">if</span> (codeSectionParts.length != 2) { throw(new ExScriptParseError(<span class="literal">'Unmatched code block markers near: "'</span> + ((codeParts[i].length &gt; 128) ? (codeParts[i].substring(0, 128) + <span class="literal">" ..."</span>) : codeParts[i]) + <span class="literal">'"'</span>)); }

		<span class="reserved">if</span> (codeSectionParts[0].length) {
			<span class="reserved">if</span> (codeSectionParts[0].match(/^\s*\=/)) {
				codeParsed += <span class="literal">"response.write("</span> + codeSectionParts[0].replace(/^\s*=\s*/, <span class="literal">''</span>).replace(/;+\s*$/, <span class="literal">''</span>) + <span class="literal">");\n"</span>;
			} <span class="reserved">else</span> {
				codeParsed += codeSectionParts[0] + <span class="literal">"\n"</span>;
			}
		}

		<span class="reserved">if</span> (codeSectionParts[1].length) {
			codeParsed += <span class="literal">"response.write(\"</span><span class="literal">" + codeSectionParts[1].replace(/\\/g, "</span>\\\\<span class="literal">").replace(/'/g, "</span>\\<span class="literal">'").replace(/"/g, '</span>\\<span class="literal">"').replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\t/g, '\\t') + "</span>\<span class="literal">");\n"</span>;
		}
	}

	<span class="reserved">return</span>(codeParsed);
}


<span class="comment">/** Not implemented yet */</span>
EvalCodeHost.<span class="reserved">prototype</span>.streamTransfer = <span class="reserved">function</span> (inStream, outStream, size) {
	<span class="comment">// TODO: Support output stream parameter for streaming of URL</span>
}


<span class="comment">/**
 * Reads a file from disk
 * <span class="attrib">@param</span> {VirtualPath|String} filepath Path to the file to open
 * <span class="attrib">@returns</span> Contents of the file
 * <span class="attrib">@type</span> String
 * <span class="attrib">@exception</span> ExFileLoadError
 * <span class="attrib">@exception</span> ExParamError
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.readFile = <span class="reserved">function</span> (filepath) {
	<span class="reserved">if</span> ((typeof filepath == <span class="literal">"string"</span>) || (filepath instanceof String))
		filepath = new <span class="reserved">this</span>.script.VirtualPath(filepath);
	<span class="reserved">if</span> (filepath instanceof VirtualPath)
		filepath = <span class="reserved">this</span>.script.mapPath(filepath)
	<span class="reserved">if</span> (!(filepath instanceof Ci.nsILocalFile))
		throw(new ExParamError(<span class="literal">"Parameter \"</span>filepath\<span class="literal">" is of an unexpected type ("</span> + typeof filepath + <span class="literal">")"</span>, 0, null, arguments));

	<span class="reserved">if</span> (!filepath.exists() || !filepath.isFile()) {
		throw(new ExFileLoadError(<span class="literal">"Unable to load file \"</span><span class="literal">" + filepath.path + "</span>\<span class="literal">""</span>, 0, null, arguments));
	}

	var fileStream = Cc[<span class="literal">"@mozilla.org/network/file-input-stream;1"</span>].
		createInstance(Ci.nsIFileInputStream);
	fileStream.init(filepath, 1, 0, false);
	var fileBinStream = Cc[<span class="literal">"@mozilla.org/binaryinputstream;1"</span>].
		createInstance(Ci.nsIBinaryInputStream);
	fileBinStream.setInputStream(fileStream);
	var fileContents = fileBinStream.readBytes(filepath.fileSize);
	
	filepath = null;
	fileBinStream = null;
	fileStream.close();
	fileStream = null;

	<span class="reserved">return</span>(fileContents);
}


<span class="comment">/**
 * Loads script file and evaluates it. Errors reading the
 *  source file results in an exception.
 * <span class="attrib">@param</span> {VirtualPath|String} filepath Path to the file to include
 * <span class="attrib">@param</span> {Boolean} rawJs (optional) Flag to indicate that
 *  the file to be included is a plain JavaScript file with
 *  no containing script tags. This is typically used when a
 *  dynamic webpage needs to include a JavaScript library
 *  written for the client side
 * <span class="attrib">@exception</span> ExScriptLoadError
 * <span class="attrib">@exception</span> ExParamError
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.require = <span class="reserved">function</span> (filepath, rawJs) {
	<span class="reserved">if</span> ((typeof filepath == <span class="literal">"string"</span>) || (filepath instanceof String))
		filepath = new <span class="reserved">this</span>.script.VirtualPath(filepath);
	<span class="reserved">if</span> (filepath instanceof VirtualPath)
		filepath = <span class="reserved">this</span>.script.mapPath(filepath)
	<span class="reserved">if</span> (!(filepath instanceof Ci.nsILocalFile))
		throw(new ExParamError(<span class="literal">"Parameter \"</span>filepath\<span class="literal">" is of an unexpected type ("</span> + typeof filepath + <span class="literal">")"</span>, 0, null, arguments));

	rawJs = !!rawJs;

	var fileContents;
	try {
		fileContents =
			(rawJs ? <span class="literal">'&lt;?js'</span> : <span class="literal">''</span>) +
			<span class="reserved">this</span>.readFile(filepath)
			+ (rawJs ? <span class="literal">'?&gt;'</span> : <span class="literal">''</span>);
	} catch (ex) {
		throw(new ExScriptLoadError(<span class="literal">"Unable to load include \"</span><span class="literal">" + filepath.path + "</span>\<span class="literal">""</span>, 0, ex, arguments));
	}

	<span class="reserved">this</span>.eval(<span class="reserved">this</span>.parse(fileContents));
}


<span class="comment">/**
 * Same as {<span class="attrib">@link</span> #require} except that errors reading the
 *  source file do not result in an exception. Failure is
 *  instead communicated by the return value
 * <span class="attrib">@param</span> {VirtualPath|String} filepath Path to the file to include
 * <span class="attrib">@param</span> {Boolean} rawJs (optional) Flag to indicate that
 *  the file to be included is a plain JavaScript 
 * <span class="attrib">@returns</span> True/False indicating success in reading the file
 * <span class="attrib">@type</span> Boolean
 * <span class="attrib">@see</span> #require
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.include = <span class="reserved">function</span> (filepath, rawJs) {
	try {
		<span class="reserved">this</span>.require(filepath, rawJs);
	} catch (e) {
		<span class="reserved">if</span> (!(e instanceof ExScriptLoadError)) { throw(e); }
		<span class="reserved">return</span>(false);
	}
	<span class="reserved">return</span>(true);
}


<span class="comment">/**
 * Opens a URL and creates a stream to be read from
 * <span class="attrib">@param</span> {String} url URL to open
 * <span class="attrib">@param</span> {Number} depth (optional) Number of redirects to allow before giving up
 * <span class="attrib">@returns</span> An array containing the channel object and an open stream
 * <span class="attrib">@type</span> [nsIHttpChannel, nsIBinaryInputStream]
 * <span class="attrib">@exception</span> ExFileLoadError
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.openNetFile = <span class="reserved">function</span> (url, depth) {
	<span class="reserved">if</span> (depth == null)
		depth = 5;

	var ioService = Cc[<span class="literal">"@mozilla.org/network/io-service;1"</span>].
		getService(Ci.nsIIOService);
	var oUrl = ioService.newURI(url, null, null);
	var channel = ioService.newChannelFromURI(oUrl);
	<span class="comment">// TODO: check for other supported channel types</span>
	<span class="reserved">if</span> (!(channel instanceof Ci.nsIHttpChannel)) { throw(new ExFileLoadError(<span class="literal">"Unable to open file due to unsupported protocol/channel"</span>, 0, null, arguments)); }
	var channelHttp = channel.QueryInterface(Ci.nsIHttpChannel);
	channelHttp.referrer = oUrl;
	var inStream = Cc[<span class="literal">"@mozilla.org/binaryinputstream;1"</span>].
		createInstance(Ci.nsIBinaryInputStream);
	inStream.setInputStream(channelHttp.open());
	<span class="reserved">if</span> (!channelHttp.requestSucceeded) {
		<span class="reserved">if</span> (channelHttp.responseStatus == <span class="literal">"302"</span> || channelHttp.responseStatus == <span class="literal">"301"</span>)
			<span class="reserved">if</span> (depth &gt; 1)
				<span class="reserved">return</span>(<span class="reserved">this</span>.openNetFile(channelHttp.getResponseHeader(<span class="literal">"location"</span>), depth - 1));
			<span class="reserved">else</span>
				throw(new ExFileLoadError(<span class="literal">"Unable to load file due to redirection limit"</span>, 0, null, arguments));
		<span class="reserved">else</span>
			throw(new ExFileLoadError(<span class="literal">"Unable to load file due to failed request"</span>, 0, null, arguments));
	}
	<span class="reserved">return</span>({
		<span class="literal">"channel"</span> : channelHttp,
		<span class="literal">"stream"</span> : inStream
		});
}


<span class="comment">/**
 * Reads a file from the network
 * <span class="attrib">@param</span> {String} url URL to open
 * <span class="attrib">@returns</span> Body of the response
 * <span class="attrib">@type</span> String
 * <span class="attrib">@exception</span> ExFileLoadError
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.readNetFile = <span class="reserved">function</span> (url) {
	var netFile;
	var sContent = <span class="literal">""</span>;

	try {
		<span class="comment">// TODO: don't assume http channel</span>
		netFile = <span class="reserved">this</span>.openNetFile(url);
		<span class="reserved">if</span> (!netFile.channel.requestSucceeded) { throw(new ExFileLoadError(<span class="literal">"Unable to load file due to failed request"</span>, 0, null, arguments)); }
		<span class="reserved">while</span> (netFile.stream.available() || sContent.length &lt; netFile.channel.contentLength) {
			sContent += netFile.stream.readBytes(netFile.stream.available());
		}
		netFile.stream.close();
		netFile.stream = null;
	} catch (ex) {
		<span class="reserved">if</span> (netFile.stream != null) {
			netFile.stream.close();
			netFile.stream = null;
		}
		throw(ExFileLoadError(<span class="literal">"Unable to load file"</span>, 0, ex, arguments));
	}

	<span class="reserved">return</span>(sContent);
}

<span class="comment">/**
 * Creates missing directories in a path
 * <span class="attrib">@param</span> {VirtualPath|String} directory Path to build out
 * <span class="attrib">@exception</span> ExParamError
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.createPath = <span class="reserved">function</span> (directory) {
	<span class="reserved">if</span> ((typeof directory == <span class="literal">"string"</span>) || (directory instanceof String))
		directory = new <span class="reserved">this</span>.script.VirtualPath(directory);
	<span class="reserved">if</span> (directory instanceof VirtualPath)
		directory = <span class="reserved">this</span>.script.mapPath(directory)
	<span class="reserved">if</span> (!(directory instanceof Ci.nsILocalFile))
		throw(new ExParamError(<span class="literal">"Parameter \"</span>directory\<span class="literal">" is of an unexpected type ("</span> + typeof directory + <span class="literal">")"</span>, 0, null, arguments));

	<span class="reserved">if</span> (directory.exists())
		<span class="reserved">return</span>;
	
	<span class="comment">/*
	 * nsIFile.parent is broken. When the path is "/", parent should be
	 * null but it turns into "/.." instead and parent.parent is "/../.." etc...
	 */</span>
	var depth = 0;
	var dirs = new Array(directory);
	var tmpDir = directory.parent;
	<span class="reserved">while</span> (depth++ &lt; 32 &amp;&amp; tmpDir != null &amp;&amp; tmpDir.path != VirtualPath.sysRoot) {
		dirs.push(tmpDir);
		tmpDir = tmpDir.parent;
	}
	<span class="reserved">while</span> (dirs.length) {
		var dir = dirs.pop();
		<span class="reserved">if</span> (!dir.exists())
			<span class="comment">/*
			 * Not happy with the 777. Perhaps do 0x0750 when
			 * VirtualPath.sysSeparator == "/" and 0x0777 when "\"
			 */</span>
			<span class="comment">//dir.create(1 /* DIRECTORY_TYPE */, 0x0755);</span>
			<span class="comment">//dir.create(Ci.nsIFile.DIRECTORY_TYPE, null);</span>
			dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0x0777);
	}
}

<span class="comment">/**
 * Copies a file
 * <span class="attrib">@param</span> {VirtualPath|String} file Path to the source file
 * <span class="attrib">@param</span> {VirtualPath|String} directory Path to copy the file to
 * <span class="attrib">@param</span> {Boolean} overwrite indicating whether existing files should be overwritten
 * <span class="attrib">@returns</span> True/False indicating copy was a success
 * <span class="attrib">@type</span> Boolean
 * <span class="attrib">@exception</span> ExParamError
 */</span>
EvalCodeHost.<span class="reserved">prototype</span>.copyFile = <span class="reserved">function</span> (file, directory, overwrite) {
	overwrite = (overwrite == null) ? false : overwrite;

	<span class="reserved">if</span> ((typeof file == <span class="literal">"string"</span>) || (file instanceof String))
		file = new <span class="reserved">this</span>.script.VirtualPath(file);
	<span class="reserved">if</span> (file instanceof VirtualPath)
		file = <span class="reserved">this</span>.script.mapPath(file)
	<span class="reserved">if</span> (!(file instanceof Ci.nsILocalFile))
		throw(new ExParamError(<span class="literal">"Parameter \"</span>file\<span class="literal">" is of an unexpected type ("</span> + typeof file + <span class="literal">")"</span>, 0, null, arguments));

	<span class="reserved">if</span> ((typeof directory == <span class="literal">"string"</span>) || (directory instanceof String))
		directory = new <span class="reserved">this</span>.script.VirtualPath(directory);
	<span class="reserved">if</span> (directory instanceof VirtualPath)
		directory = <span class="reserved">this</span>.script.mapPath(directory)
	<span class="reserved">if</span> (!(directory instanceof Ci.nsILocalFile))
		throw(new ExParamError(<span class="literal">"Parameter \"</span>directory\<span class="literal">" is of an unexpected type ("</span> + typeof directory + <span class="literal">")"</span>, 0, null, arguments));

	<span class="reserved">if</span> (!file.exists())
		<span class="reserved">return</span>(false);

	var destFile = directory.clone();
	destFile.append(file.leafName);

	<span class="reserved">if</span> (destFile.exists())
		<span class="reserved">if</span> (!overwrite)
			<span class="reserved">return</span>(false);
		<span class="reserved">else</span>
			destFile.remove(true);

	<span class="reserved">this</span>.createPath(directory);

	file.copyTo(directory, <span class="literal">""</span>);

	<span class="reserved">return</span>(true);
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>JsWs</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Nov  8 22:50:16 2007</div>
</body>
</html>
